<?php
/**
 * Created by PhpStorm.
 * User: 29620
 * Date: 2021/11/22
 * Time: 11:03
 */
namespace app\admin\controller;

use app\admin\model\Goods;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Good extends BaseController
{
    public function goodList()
    {
        $param = Request::param();

        $where = [];
        if(isset($param['keywords']) && $param['keywords']<>'') $where['keywords'] = $param['keywords'];
        if(isset($param['is_hot']) && $param['is_hot']<>'')     $where['is_hot'] = $param['is_hot'];
        if(isset($param['is_show']) && $param['is_show']<>'')     $where['is_show'] = $param['is_show'];
        if(isset($param['is_down']) && $param['is_down']<>'')     $where['is_down'] = $param['is_down'];
        if(isset($param['cid']) && !empty($param['cid']))     $where['cid'] = $param['cid'];

        if (isset($param['k_time']) && $param['k_time']<>'')      $where['k_time'] = $param['k_time'];
        if (isset($param['j_time']) && $param['j_time']<>'')      $where['j_time'] = $param['j_time'];
        if (isset($param['g_price']) && $param['g_price']<>'')      $where['g_price'] = $param['g_price'];
        if (isset($param['d_price']) && $param['d_price']<>'')      $where['d_price'] = $param['d_price'];

        $list = Goods::getGoods($where,$param);
        View::assign('list',$list);

        $cateA = Db::name('category')->order('sort')->select()->toArray();
        $cate = $this->getCate($cateA,0);
        View::assign('cate',$cate);


        return view('',$where);
    }

    public function getCate($cateA,$parentid)
    {
        $cate = [];
        foreach ($cateA as $v){
            if($v['parentid'] == $parentid){
                $cate[$v['id']] = $v;
                $cate[$v['id']]['son'] = $this->getCate($cateA,$v['id']);
            }
        }
        return $cate;
    }



    public function goodAdd()
    {
        return view();
    }

    public function goodEdit()
    {
        return view();
    }
}